package main;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import views.HistoryView;
import views.OperandView;
import views.StackView;

import controller.BaseController;
import controller.CalculateController;
import controller.FormatController;
import controller.HistoryController;
import controller.OperandController;
import controller.StackController;

import multiformat.Calculator;


public class Runner extends JFrame {
	
	private static final long serialVersionUID = 1L;

	private Calculator model;
	
	private OperandController input;
	private CalculateController calc;
	private BaseController base;
	private FormatController format;
	private HistoryController btnHistory;
	private StackController btnStack;
	
	private OperandView view;
	private HistoryView history;
	private StackView stack;
		
	public Runner() {

		this.setSize(215,250);
		
		//declare panels
		JPanel north = new JPanel();
		north.setLayout(new GridLayout(2,1));
		
		JPanel center = new JPanel();
		center.setLayout(new GridLayout(1,2));
		
		JPanel east = new JPanel();
		east.setLayout(new GridLayout(2,1));
		
		JPanel south = new JPanel();
		south.setLayout(new GridLayout(1,2));
		
		// initialize model
		this.model 			= 	new Calculator();
	
		// initialize controllers
		this.input 			= 	new OperandController(model);
		this.calc 			= 	new CalculateController(model);
		this.base 			= 	new BaseController(model);
		this.format 		= 	new FormatController(model);
		this.btnHistory 	= 	new HistoryController(model);
		this.btnStack		=	new StackController(model);
		
		// initialize views
		this.view			=	new OperandView();
		this.history		=	new HistoryView();
		this.stack			=	new StackView();
		
		this.history.setLocationRelativeTo(this);
		this.stack.setLocationRelativeTo(this);
		
		// add views to model
		this.model.addActionListener(view);
		this.model.addActionListener(history);
		this.model.addActionListener(stack);
		
		// create panels
		north.add(view);
		north.add(input);
		
		east.add(base);
		east.add(format);
				
		center.add(calc);
		center.add(east);
		
		south.add(btnHistory);
		south.add(btnStack);
		
		//add panels to JFrame
		this.add(north,BorderLayout.NORTH);
		this.add(center,BorderLayout.CENTER);
		
		this.add(south,BorderLayout.SOUTH);
		
		
		this.setTitle("MultiFormat calc");
		this.setResizable(false);
		this.validate();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		
	}
	
	
}
